package com.tomvian.twodee.common.interactions 
{
	import flash.display.DisplayObject;
	import com.tomvian.twodee.common.actions.Action;
	import com.tomvian.twodee.common.actions.Dying;
	/**
	 * Hazards
	 * @author Thomas Vian
	 */
	public class Hazards extends Interaction
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public var hurt:Action;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function Hazards(hazards:Array, hurt:Action = null) 
		{
			super(hazards);
			this.hurt = hurt;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function interact():void 
		{
			if (enabled)
			{
				wasInteracting = interacting;
				interacting = false;
				
				for (var i:uint = 0, l:uint = interactiveObjects.length; i < l; i++)
				{
					var hazard:DisplayObject = interactiveObjects[i];
					
					if (hazard.hitTestObject(actor))
					{
						interacting = true;
						
						if (!wasInteracting)
						{
							currentObject = hazard;
							
							if(hurt) actor.currentAction = hurt;
						}
						break;
					}
				}
			}
		}
	}
}